package com._520it.crm.service.impl;

import com._520it.crm.domain.Client;
import com._520it.crm.domain.TransferRecord;
import com._520it.crm.mapper.ClientMapper;
import com._520it.crm.mapper.TransferRecordMapper;
import com._520it.crm.page.PageResult;
import com._520it.crm.query.QueryObject;
import com._520it.crm.service.ITransferRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;
@Service
public class TransferRecordServiceImpl implements ITransferRecordService {
    @Autowired
    TransferRecordMapper transferRecordMapper;
    @Autowired
    ClientMapper clientMapper;
    @Override
    public int deleteByPrimaryKey(Integer id) {
        transferRecordMapper.deleteByPrimaryKey(id);
        return 0;
    }



    @Override
    public PageResult query(QueryObject qo) {
        Integer totalCount = transferRecordMapper.queryforCount(qo);
        if (totalCount==0){
            return new PageResult(0, Collections.EMPTY_LIST);
        }
        List<Client> data = transferRecordMapper.queryforList(qo);
        return new PageResult(totalCount,data);
    }
    //业务方法
    @Override
    public void insert(TransferRecord transferRecord ,Long clientId) {
        System.out.println(clientId);
        transferRecord.setTransferTime(new Date());
        clientMapper.transferById(clientId,transferRecord.getManagerId());
        transferRecord.getManagerId();
        transferRecordMapper.insert(transferRecord);

    }

    @Override
    public void deleteall() {
        transferRecordMapper.deleteall();
    }
}
